package com.xjgc.common.utils;

import org.springframework.util.StringUtils;

public class StringUtil {
    /*在不以000开头的字符串添加000*/
    public static String addPrefix(String oldStr) {
        if (StringUtils.isEmpty(oldStr)) {
            return null;
        }
        if (!oldStr.startsWith("000")) {
            oldStr = "000" + oldStr;
        }
        return oldStr;
    }

    /**
     * 从字符串右侧开始,提取连续数值
     *
     * @param source
     * @return
     */
    public static String extractNumberRight(String source) {
        StringBuffer sb = new StringBuffer();
        char[] chars = source.toCharArray();
        for (int i = chars.length - 1; i >= 0; i--) {
            char c = chars[i];
            if (Character.isDigit(c) || '.' == c) {
                sb.insert(0, c);
            }
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        String str = "<output><output>";
    }
}
